﻿@{
    ViewBag.Title = "Chuồng nuôi";
}
@using ProjectThuCung.Models

@if(ViewBag.count !=0)
{
    <div class="wrapper" style="margin-bottom:10px">
    
        @foreach (var item in (List<SanPham>)ViewBag.data)
        {
            <div class="products product_item" style="margin-left:10px;height:300px;">
                <div class="inner-product-home">
                    <a href="/SanPham/ThongTinSanPham?sanpham=@item.TenSanPham&id=@item.SanPhamID">
                        <img width="171" height="214" class="lazy img-product" src="@item.HinhAnh" alt="" data-original="@item.HinhAnh" style="display: block; "></a> 
                </div> 
                <div class="infor-text-pro">                    
                        @{
                            if(item.TenSanPham.Count() <=30)
                            {
                                <a title="@item.TenSanPham" style="height: 35px;display: inline-block;" href="/SanPham/ThongTinSanPham/@item.LoaiSanPham.SubLoaiSanPham?loaisanpham=@item.LoaiSanPham.TenLoaiSanPham&phanloai=@item.LoaiSanPham.LoaiSanPhamID&sanpham=@item.TenSanPham&id=@item.SanPhamID"> @item.TenSanPham</a>
                            }
                            else
                            {
                                <a title="@item.TenSanPham" style="height: 35px;display: inline-block;" href="/SanPham/ThongTinSanPham/@item.LoaiSanPham.SubLoaiSanPham?loaisanpham=@item.LoaiSanPham.TenLoaiSanPham&phanloai=@item.LoaiSanPham.LoaiSanPhamID&sanpham=@item.TenSanPham&id=@item.SanPhamID"> @item.TenSanPham.Substring(0,30)...</a>
                            }
                        }
		            <br>		          					          	
                    <strong>@item.Gia<span>.000đ</span></strong>
		        </div>
            </div>
        }
    </div>
    
    <div class ="page">
        <ul>
            @{
                if(ViewBag.count < 1)
                {
                    if (ViewBag.loaisanpham != null || ViewBag.phanloai != null)
                    {
                        if (ViewBag.trang == null || int.Parse(ViewBag.trang) <= 1)
                        {
                            @Html.Raw("Prev  ")
                            @Html.Raw("[1]")
                            for (int i = 2; i <= ViewBag.count; i++)
                            {
                                if(i <= 6)
                                {
                                    <li style ="background:#bceacf">@Html.ActionLink(i.ToString(), "Chuong", "SanPham", new { loaisanpham = ViewBag.loaisanpham, phanloai = ViewBag.phanloai, trang = i},null)</li>
                                }
                            }
                            <li style ="background:#bceacf">@Html.ActionLink("Next", "Chuong", "SanPham", new { loaisanpham = ViewBag.loaisanpham, phanloai = ViewBag.phanloai, trang = 2},null)</li>
                        }
                        else
                        {
                            <li style ="background:#bceacf">@Html.ActionLink("Prev", "Chuong", "SanPham", new { loaisanpham = ViewBag.loaisanpham, phanloai = ViewBag.phanloai, trang = int.Parse(ViewBag.trang) - 1},null)</li>
            
                            if(ViewBag.count <= int.Parse(ViewBag.trang))
                            {
                                for (int i = 1; i < ViewBag.count; i++)
                                {
                                    if (i >= (ViewBag.count - 5))
                                    {
                                        if (i == int.Parse(ViewBag.trang))
                                        {
                                            @Html.Raw("[" + i +"]");
                                        }
                                        else
                                        {
                                            <li style ="background:#bceacf">@Html.ActionLink(i.ToString(), "Chuong", "SanPham", new { loaisanpham = ViewBag.loaisanpham, phanloai = ViewBag.phanloai, trang = i},null)</li>
                                        }
                                    }
                                }
                                @Html.Raw("[" + ViewBag.count + "]");
                                @Html.Raw("  Next")
                            }
                            else
                            {
                                for (int i = 1; i <= ViewBag.count; i++)
                                {
                                    if (i >= (int.Parse(ViewBag.trang) - 5) && i <= (int.Parse(ViewBag.trang) + 5))
                                    {
                                        if (i == int.Parse(ViewBag.trang))
                                        {
                                            @Html.Raw("[" + i +"]");
                                        }
                                        else
                                        {
                                            <li style ="background:#bceacf">@Html.ActionLink(i.ToString(), "Chuong", "SanPham", new { loaisanpham = ViewBag.loaisanpham, phanloai = ViewBag.phanloai, trang = i},null)</li>
                                        }
                                    }
                                }
                                <li style ="background:#bceacf">@Html.ActionLink("Next", "Chuong", "SanPham", new { loaisanpham = ViewBag.loaisanpham, phanloai = ViewBag.phanloai, trang = int.Parse(ViewBag.trang) + 1},null)</li>
                            }
                        }
                    }
                    else
                    {
                        if (ViewBag.trang == null || int.Parse(ViewBag.trang) <= 1)
                        {
                            @Html.Raw("Prev  ")
                            @Html.Raw("[1]")
                            for (int i = 2; i <= ViewBag.count; i++)
                            {
                                if( i<= 6)
                                {
                                    <li style ="background:#bceacf">@Html.ActionLink(i.ToString(), "Chuong", "SanPham", new { trang = i},null)</li>
                                }
                            }
                            <li style ="background:#bceacf">@Html.ActionLink("Next", "Chuong", "SanPham", new { trang = 2},null)</li>
                        }
                        else
                        {
                            <li style ="background:#bceacf">@Html.ActionLink("Prev", "Chuong", "SanPham", new { trang = int.Parse(ViewBag.trang) - 1},null)</li>
                    
                            if(ViewBag.count <= int.Parse(ViewBag.trang))
                            {
                                for (int i = 1; i < ViewBag.count; i++)
                                {
                                    if (i >= (ViewBag.count - 5))
                                    {
                                        if (i == int.Parse(ViewBag.trang))
                                        {
                                            @Html.Raw("[" + i +"]");
                                        }
                                        else
                                        {
                                            <li style ="background:#bceacf">@Html.ActionLink(i.ToString(), "Chuong", "SanPham", new { trang = i},null)</li>
                                        }
                                    }
                                }
                                @Html.Raw("[" + ViewBag.count + "]");
                                @Html.Raw("  Next")
                            }
                            else
                            {
                                for (int i = 1; i <= ViewBag.count; i++)
                                {
                                    if (i >= (int.Parse(ViewBag.trang) - 5) && i <= (int.Parse(ViewBag.trang) + 5))
                                    {
                                        if (i == int.Parse(ViewBag.trang))
                                        {
                                            @Html.Raw("[" + i +"]");
                                        }
                                        else
                                        {
                                            <li style ="background:#bceacf">@Html.ActionLink(i.ToString(), "Chuong", "SanPham", new { trang = i},null)</li>
                                        }
                                    }
                                }
                                <li style ="background:#bceacf">@Html.ActionLink("Next", "Chuong", "SanPham", new { trang = int.Parse(ViewBag.trang) + 1},null)</li>
                            }
                        }
                     }
                }
            }
        </ul>
    </div>
                
}